home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / sbin / start-gateway.z / start-gateway
Encoding:
Text File  |  1997-07-30  |  7.3 KB  |  226 lines

  1. #!/usr/bin/perl5
  2. #
  3. # start-gateway
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: start-gateway,v 1.13 1997/05/01 17:54:37 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. $ifcmd = "/usr/OnRamp/bin/htnetwork";
  25. $hostsf = "/etc/hosts";
  26. $hoststmp = "/etc/hosts.tmp";
  27.  
  28. sub replace_host_entry {
  29.     local($old_ip) = $_[0];
  30.     local($new_ip) = $_[1];
  31.     local($new_hs) = $_[2];
  32.     local($new_dm) = $_[3];
  33.     open(IN,"< $hostsf");
  34.     open(OUT,"> $hoststmp");
  35.     while(<IN>) {
  36.     if (/^#/) {
  37.         print OUT $_;
  38.         next;
  39.     }
  40.     if (/^$old_ip/) {
  41.         print OUT "# ".$_;
  42.         print OUT "$new_ip\t$new_hs.$new_dm\t$new_hs\n";
  43.         next;
  44.     }
  45.     print OUT $_;
  46.     }
  47.     rename($hoststmp, $hostsf);
  48. }
  49.  
  50. #
  51. # Get information from administrator.
  52. #
  53.  
  54. if ($< !=0) {
  55.     print "You need to be Superuser (root) to run this script.\n";
  56.     exit 1;
  57. }
  58.  
  59. @ifs = `$ifcmd`;
  60. ($num, $ifnm, $rest) = split(/:/, $ifs[0]);
  61. @ifconfs = `/usr/etc/ifconfig $ifnm`;
  62. for ($i = 0; $i <= $#ifconfs; $i++) {
  63.    @fields = split(/\s+/, $ifconfs[$i]);
  64.    for ($j = 0; $j <= $#fields; $j++) {
  65.     if ($fields[$j] eq "inet") {
  66.         $o_address = $fields[$j+1];
  67.     }
  68.     elsif ($fields[$j] eq "netmask") {
  69.         $o_netmask = $fields[$j+1];
  70.     }
  71.    }
  72. }
  73. chop($o_hstname = `/usr/bsd/hostname`);
  74. if ($o_hstname =~ /^([^\.]*)\./) { $o_hstname = $1; }
  75. ($name, $dummyb, $dummyc, $dummyd, @dummye) = gethostbyname($o_hstname);
  76. $name =~ /^\w+\.(.*)$/;
  77. $o_domainname = $1;
  78.  
  79. print "\nWelcome to your Silicon Graphics WebFORCE Internet Gateway server!\n";
  80. print "There are a few simple steps to connect your server to the Internet:\n\n";
  81. print "First, use this terminal window to configure your server to\n",
  82.       "communicate with your local network by means of an IP connection.\n";
  83. print "Currently, you are using a serial cable connection to communicate\n",
  84.       "between your server and a terminal device (such as a VT-100 terminal\n",
  85.       "or a PC-compatible, Macintosh, or Indy computer running terminal\n",
  86.       "emulation software), but the serial connection will be replaced.\n\n";
  87.  
  88. print "After you configure your server using this terminal window, you will\n",
  89.       "configure your server to communicate with the Internet. For this\n",
  90.       "step, you will use a Web browser on your PC-compatible, Macintosh \n",
  91.       "or Indy computer. Your computer will communicate with your server \n",
  92.       "through an Ethernet cable.\n";
  93.  
  94. print "\nThe current configuration of your server is:\n\n";
  95. print "Hostname: $o_hstname\n";
  96. print "Domain name: $o_domainname\n";
  97. print "IP Address: $o_address\n";
  98. print "Netmask: $o_netmask\n\n";
  99.  
  100. print "You must change these factory settings to connect your server to the\n",
  101.       "Internet. Most of the information that you need to make these changes\n",
  102.       "is supplied by your Internet service provider (ISP). Make sure you\n",
  103.       "have the appropriate information from your ISP, and follow the\n",
  104.       "steps below.\n";
  105.  
  106. do {
  107.     do {
  108.     print "\nA hostname uniquely identifies your Silicon Graphics Internet\n",
  109.        "Gateway server.  By convention, hostnames contain only lowercase\n",
  110.        "letters.\n\n";
  111.  
  112.     print "Enter a hostname for this server: [$o_hstname] ";
  113.     chomp($hstname = <STDIN>);
  114.     if ($hstname eq "") {
  115.         $hstname = $o_hstname;
  116.     }
  117.     $hstname =~ s/\..*//;
  118.     if (($hstname ne $o_hstname) && check_hostname($hstname)) {
  119.         print "Invalid Hostname '$hstname', Please consult the\n";
  120.         print "administrator's manual for correct Hostname syntax.\n";
  121.         $hstname = "";
  122.     }
  123.     if ($hstname ne "") {
  124.         do {
  125.         print "\nEach organization on the Internet is known by its domain name.\n",
  126.            "Domain names usually contain two (or three) segments, separated by\n",
  127.            "periods. Your ISP assigns domain names. (Example: aspen.com)\n\n";
  128.         print "Enter the Domainname for this server: [$o_domainname] ";
  129.         chomp($dmname = <STDIN>);
  130.         if ( ($o_domainname eq "") && $dmname && check_hostname($dmname)) {
  131.             print "Invalid Domainname '$dmname',  Please consult the\n";
  132.             print "administrator's manual for correct Domainname syntax.\n";
  133.             $dmname = "";
  134.         }
  135.         } until ($dmname || $o_domainname);
  136.         if ($dmname eq "") {
  137.         $dmname = $o_domainname;
  138.         }
  139.     }
  140.     } until ($hstname);
  141.  
  142.     do {
  143.     print "\nThe primary network interface connects the server to your local\n",
  144.        "area network.  Use an IP address that you obtained from your ISP as\n",
  145.        "the IP address for the primary network interface. (Example: 196.45.23.4)\n\n";
  146.     print "Enter the IP Address of the primary network interface: [$o_address] ";
  147.     chomp($address = <STDIN>);
  148.     if ($address eq "") {
  149.         $address = $o_address;
  150.     }
  151.     if ((address ne $o_address) && check_ipaddr($address)) {
  152.         print "Invalid IP Address '$address', Please consult your\n";
  153.         print "Network administrator for the correct IP Address.\n";
  154.         $address = "";
  155.     }
  156.     } until ( ($address) && ($address ne "192.0.2.1") );
  157.  
  158.     print "\nThe netmask is used in conjunction with the IP address. In most\n",
  159.       "cases, you can use the default netmask.\n\n";
  160.     print "Enter netmask for this interface: [$o_netmask] ";
  161.     chomp($netmask = <STDIN>);
  162.     if ($netmask eq "") {
  163.     $netmask = $o_netmask;
  164.     }
  165.  
  166.     # Verify Netmask
  167.  
  168.     print "\n\nVerify Configuration.  You have entered:\n";
  169.     print "Hostname: $hstname\n";
  170.     print "Domainname: $dmname\n";
  171.     print "IP Address: $address\n";
  172.     if ($netmask) {
  173.     print "Netmask: $netmask\n";
  174.     } else {
  175.     print "Netmask is default\n";
  176.     }
  177.  
  178.     print "\nIs this correct? [y/n]: ";
  179.     $answer = <>;
  180. } until ($answer =~ /^y/i);
  181.  
  182. #
  183. # Update /etc/sys_id with new hostname.
  184. #
  185. if ($hstname ne $o_hstname) {
  186.     open(SYSID, ">/etc/sys_id") || die "Failed to open /etc/sys_id.\n";
  187.     print SYSID "$hstname\n";
  188.     close(SYSID);
  189. }
  190.  
  191. #
  192. # Update /etc/hosts.
  193. #
  194. if (($hstname ne $o_hstname) || ($address ne $o_address)) {
  195.     replace_host_entry($o_address, $address, $hstname, $dmname);
  196. }
  197.  
  198. #
  199. # Update ifconfig-1.options if netmask was specified.
  200. #
  201. if ($netmask ne $o_netmask) {
  202.     open(CFG, ">/etc/config/ifconfig-1.options") ||
  203.     die "Failed to write ifconfig-1.options file.\n";
  204.     print CFG "netmask $netmask";
  205.     close(CFG);
  206. }
  207.  
  208. `/etc/chkconfig network on`;
  209.  
  210. print "You now need to reboot your server to put your changes in effect.\n",
  211.       "After your server reboots, complete these steps:\n",
  212.       "\t1. Open a Web browser on your computer\n",
  213.       "\t2. Open the URL \"http://$address:2077/\" in the browser\n",
  214.       "\t3. Select \"Setup Tasks\" on the WebFORCE Internet Gateway Web page\n",
  215.       "\t   to continue connecting to the internet.\n";
  216.  
  217. print "After your server reboots, you can close this terminal window on your\n",
  218.       "terminal (or personal computer) window.\n\n";
  219.  
  220. print "Reboot server now ? [y|n]";
  221. $answer = <>;
  222. if ($answer =~ /^y/i) {
  223.     system ("/etc/init 6");
  224. }
  225. exit 0;
  226.